package com.onehouse.infrastructure.repository.checkIn;

import com.onehouse.domain.checkIn.adapter.repository.IRoomRateRepository;
import com.onehouse.domain.checkIn.model.valobj.RoomRate;
import com.onehouse.infrastructure.dao.RoomRateDao;
import com.onehouse.infrastructure.dao.po.RoomRatePO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

@Repository
public class RoomRateRepository implements IRoomRateRepository {
    @Resource
    private RoomRateDao roomRateDao;

    @Override
    public void saveRate(String checkInRoomId, RoomRate roomRate) {
        RoomRatePO po = new RoomRatePO();
        po.setCheckInRoomId(checkInRoomId);
        po.setAmount(roomRate.getAmount());
        po.setPaymentId(roomRate.getPaymentId());
        roomRateDao.insert(po);
    }

    @Override
    public void updateRate(String checkInRoomId, String paymentId) {
        RoomRatePO po = new RoomRatePO();
        po.setCheckInRoomId(checkInRoomId);
        po.setPaymentId(paymentId);
        roomRateDao.update(po);
    }

    @Override
    public RoomRate getRate(String checkInRoomId) {
        RoomRatePO po = roomRateDao.selectByCheckInRoomId(checkInRoomId);
        if (po == null) {
            return null;
        }
        return RoomRate.builder()
                .amount(po.getAmount())
                .paymentId(po.getPaymentId())
                .build();
    }
} 